﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SaleSoft.Constants;
using SaleSoft.Models;

namespace SaleSoft.Helper {
    public static class SessionHelper {

        #region Tab Section
        /// <summary>
        /// Active tab trên menu chính
        /// </summary>
        /// <param name="TabName">Số tương ứng với tab</param>
        public static void ActiveTab ( int TabName ) {
            HttpContext.Current.Session[SessionConstants.CURRENT_TAB] = TabName;
        }

        /// <summary>
        /// Get tab đang active tương ứng trên menu
        /// </summary>
        /// <returns></returns>
        public static int GetCurrentTab () {
            if (HttpContext.Current.Session[SessionConstants.CURRENT_TAB] != null) {
                return Convert.ToInt32(HttpContext.Current.Session[SessionConstants.CURRENT_TAB]);
            } else {
                return SessionConstants.Tab_TrangChu;
            }
        }

        #endregion

        #region Properties Section
        public static string UserName {
            get {
                return "admin";
            }
            set { }
        }
        #endregion

        #region Login Section
        public static void SetUser ( ds_nhanvienquanly user ) {
            HttpContext.Current.Session[SessionConstants.IS_USER_LOGIN] = true;
            HttpContext.Current.Session[SessionConstants.USER_NAME] = user.tendangnhap;
        }

        public static void ClearUser () {
            HttpContext.Current.Session[SessionConstants.IS_USER_LOGIN] = false;
            HttpContext.Current.Session[SessionConstants.USER_NAME] = null;
        }

        public static bool IsLogin () {
            try {
                return (bool)HttpContext.Current.Session[SessionConstants.IS_USER_LOGIN];
            } catch {

                return false;
            }
        }
        #endregion
    }
}